<!-- 成控部：工厂生产作业-指令资料输入 蹇泽阳 -->
<template>
  <div class="app-container">
    <Find :OriginalFilter="{ static: true }" :formList="formList" @findClicked="findClicked" />
    <div class="mt10 flex" style="width: 100%; background-color: white">
      <el-card shadow="never" :body-style="{ padding: '10px 0px 0px 5px' }">
        <div class="flex AIC">
          <h1 class="f16">指令明细</h1>
          <el-button class="ml10" type="primary" size="default" style="background-color: aquamarine" @click="getTableList(3)">根据指令排序</el-button>

          <el-button
            class="primaryBth ml10"
            type="primary"
            size="default"
            @click="
              () => {
                drawer = true
                value = 0
                getTableList999(0)
              }
            "
            >PO号码明细</el-button
          >
          <el-button
            class="primaryBth"
            type="primary"
            size="default"
            @click="
              () => {
                drawer = true
                value = 1
                getTableList999(1)
              }
            "
            >指令用量明细</el-button
          >
          <el-button
            class="primaryBth"
            type="primary"
            size="default"
            @click="
              () => {
                drawer = true
                value = 2
                getTableList999(2)
              }
            "
            >配色注意事项</el-button
          >
          <el-button
            class="primaryBth"
            type="primary"
            size="default"
            @click="
              () => {
                drawer = true
                value = 3
                getTableList999(3)
              }
            "
            >型体配宣明细</el-button
          >
          <el-button
            class="primaryBth"
            type="primary"
            size="default"
            @click="
              () => {
                drawer = true
                value = 4
                getTableList999(4)
              }
            "
            >配色BOM资料</el-button
          >
          <el-button
            class="primaryBth"
            type="primary"
            size="default"
            @click="
              () => {
                drawer = true
                value = 5
                getTableList999(5)
              }
            "
            >各节点生产明细</el-button
          >
        </div>
        <Table
          :tableData="tableData"
          :tableHeader="tableHeader"
          :selection="true"
          :summaryData="summaryData"
          summary
          @currentRow="currentRow"
          :isLoading="isLoading"
          :getTableList="getTableList"
          @confirmChange="confirmChange"
          @selectList="selectTableList"
          @currentRow1="dbClick"
          @selectValChange="selectValChange"
        />
        <Find :OriginalFilter="{ static: true }" :formList="formList2" :searchImg="false" @findClicked="findClicked2"> </Find>
      </el-card>
      <el-card shadow="never" :body-style="{ padding: '10px 5px 0px' }" style="width: 180px">
        <div class="flex">
          <h1 class="f16">指令明细</h1>
          <el-button type="primary" size="default" @click="saveTableList2">保存</el-button>
        </div>
        <div ref="JRef">
          <Table
            @handleKeyDown="handleKeyDown"
            :tableHeader="tableHeader2"
            :tableData="tableData2"
            :summaryData="summaryData2"
            summary
            :getTableList="getTableList2"
            @inputChange="confirmChange2"
          />
        </div>
      </el-card>
    </div>
    <el-card shadow="never" :body-style="{ padding: '5px' }">
      <PageModule :PageData="{ total, buttonS: true }" @pageSizeChange="handleSizeChange" @pageChange="handleCurrentChange" />
    </el-card>

    <!-- 抽屉 -->
    <el-drawer v-model="drawer" :direction="'ttb'" :with-header="false" :size="'65%'">
      <span @click="drawer = false" style="float: right; cursor: pointer; color: rgb(7, 7, 7)">X</span>
      <div class="flex AIC" style="flex-direction: column">
        <el-card shadow="always" :body-style="{ padding: '10px 10px 10px' }" style="width: 100vw">
          <div class="flex AIC">
            <el-select style="width: 200px" v-model="value" filterable placeholder="PO号码明细" @change="(val: any) => EndSelectVal(val)">
              <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value" />
            </el-select>

            <div v-if="value === 0" class="flex ml20 AIC">
              <el-select
                style="width: 150px"
                v-model="value2"
                clearable
                filterable
                placeholder="美码/英码"
                @change="(val: any) => getPoNumberSizeData()"
                :disabled="disabledValue2"
              >
                <el-option v-for="item in options2" :key="item.value" :label="item.label" :value="`${item.value}  ${item.label}`"> </el-option>
              </el-select>
              <JDialog
                :tableHeader="JDialogHeader"
                :width="60"
                @confirm="dialogConfirm"
                @removeOne="removeOne"
                :currentTableRow="currentTable4Row"
                @clickAdd="clickAdd"
                @clickEdit="clickEdit"
                :unEdit="false"
              >
              </JDialog>
            </div>

            <div v-if="value === 5" class="ml10 flexSB mr45" style="flex: 1">
              <el-button class="primaryBth" type="primary" size="default" @click="getSoleDetailsAdd">取大底入货号码明细</el-button>
              <el-button class="primaryBth" type="primary" size="default" @click="getStitchDetailsAdd">取鞋面生产号码明细</el-button>
              <el-button class="primaryBth" type="primary" size="default" @click="getLastDetailsAdd">取成型生产号码明细</el-button>
            </div>
          </div>
          <!-- PO号码明细 -->
          <div class="mt15" v-if="value === 0">
            <JTable
              :showToolTip="false"
              :tableHeader="tableHeader4"
              :tableData="tableData4"
              :summaryData="summaryData6"
              summary
              @currentRow="currentRow4"
              @inputChange="confirmChange4"
            />
          </div>
          <!-- 指令用量明细 -->
          <div class="mt15" v-if="value === 1">
            <Table @confirmChange="confirmChange5" :tableHeader="tableHeader5" :tableData="tableData5" />
          </div>
          <!-- 配色注意事项 -->
          <div class="mt15" v-if="value === 2">
            <Table :tableHeader="tableHeader6" :tableData="tableData6" />
          </div>
          <!-- 型体配宣明细 -->
          <div class="mt15" v-if="value === 3">
            <Table :tableHeader="tableHeader7" :tableData="tableData7" />
          </div>
          <!-- 配色BOM资料 -->
          <div class="mt15" v-if="value === 4">
            <Table :tableHeader="tableHeader8" :tableData="tableData8" />
          </div>
          <!-- 各节点生产明细 -->
          <div class="mt15 flexSB" v-if="value === 5" style="margin-left: 180px">
            <Table :summaryData="summaryData3" summary :tableHeader="tableHeader9" :tableData="tableData9" class="mr55" />
            <Table :summaryData="summaryData4" summary :tableHeader="tableHeader10" :tableData="tableData10" class="mr55" />
            <Table :summaryData="summaryData5" summary :tableHeader="tableHeader11" :tableData="tableData11" />
          </div>
        </el-card>
      </div>
    </el-drawer>

    <!-- 指令复制 -->
    <el-dialog v-model="lotNoVisible" title="指令复制" width="30%">
      <el-form-item label="已有指令">
        <el-input v-model="currentLotNo" disabled></el-input>
      </el-form-item>
      <el-form-item label="待复制指令">
        <el-input v-model="copyLotNo"></el-input>
      </el-form-item>
      <el-button type="primary" class="primaryBth" @click="ClickCopyLotNo" style="float: right">复制</el-button>
    </el-dialog>
  </div>
</template>
<script lang="ts">
import { defineComponent } from 'vue'
import 'dayjs/locale/zh-cn'
import { ElMessage, ElMessageBox } from 'element-plus'
import Synchronization from '@/utils/Synchronization'
import SynchronizationLoginWork from '@/utils/SynchronizationLoginWork'
import { formateData } from '@/plugins/mixinJ'
import router from '@/router'
import { debounce } from 'lodash'
import fileRequest from '@/utils/fileRequest'
import JMessage from '@/utils/JMessage'
import service from '@/utils/request'
import LoginWork from '@/utils/LoginWork'
export default defineComponent({
  name: 'InstructionDataEntry'
})
</script>
<script lang="ts" setup>
import { i18n, Jzhcn } from '@/i18n'
import { nextTick, onMounted, reactive, ref, watch } from 'vue'
const drawer = ref(false)

const currentLotNo = ref('')
const copyLotNo = ref('')
const lotNoVisible = ref(false)
const value2 = ref('')

const tableData12 = ref([]) as any
const isLoading12 = ref(false)
const copyOptions = ref([])
const getTableList12 = async () => {
  isLoading12.value = true
  let { styleToDetail } = await Synchronization.get<any, any>('/style/getCondition')
  tableData12.value = styleToDetail
  copyOptions.value = styleToDetail
  isLoading12.value = false
}

// 表一模块
const formList = ref<any>([
  {
    type: 'input',
    inputPlaceholder: '请输入指令',
    inputValue: ''
  },
  {
    type: 'input',
    inputPlaceholder: '请输入工厂型体',
    inputValue: ''
  },
  {
    type: 'selectJ',
    selectP: '颜色名称  颜色代码',
    selectValue: '',
    selectOptions: []
  },
  {
    type: 'select',
    selectValue: '',
    selectLabel: '',
    selectP: '新旧型体',
    selectOptions: [
      {
        optionValue: '新款',
        optionLabel: '新款'
      },
      {
        optionValue: '旧款',
        optionLabel: '旧款'
      }
    ]
  },
  {
    type: 'input',
    inputPlaceholder: '请输入合同号',
    inputValue: ''
  },

  {
    type: 'date',
    dateLabel: '下单日期',
    dateValue: ''
  },
  {
    type: 'date',
    dateLabel: '客人交期',
    dateValue: ''
  },
  {
    type: 'select',
    selectValue: '',
    selectP: '品牌',
    selectLabel: '',
    selectOptions: []
  },
  {
    type: 'input',
    inputPlaceholder: '请输入客人货号',
    inputValue: ''
  },
  {
    type: 'select',
    selectValue: '',
    selectP: '冲刀',
    selectLabel: '',
    selectOptions: []
  },
  {
    type: 'select',
    selectValue: '',
    selectP: '楦头',
    selectLabel: '',
    selectOptions: []
  },
  {
    type: 'select',
    selectValue: '',
    selectP: '底模',
    selectLabel: '',
    selectOptions: []
  },
  {
    type: 'select',
    selectValue: '',
    selectP: '大底厂商',
    selectLabel: '',
    selectOptions: []
  },
  {
    type: 'select',
    selectValue: '',
    selectP: '季度',
    selectLabel: '',
    selectOptions: []
  },
  {
    type: 'button',
    checkboxLabel: '新增指令'
  },
  {
    type: 'button',
    checkboxLabel: '置空',
    bgColor: '#1890FF'
  },
  {
    type: 'button',
    checkboxLabel: '指令复制'
  },
  {
    type: 'button',
    checkboxLabel: '整单删除'
  },
  // {
  //   type: 'button',
  //   checkboxLabel: '计算预补量',
  // },
  {
    type: 'button',
    checkboxLabel: '计算中间码'
  },
  {
    type: 'button',
    checkboxLabel: '检核',
    bgColor: '#1890FF'
  },
  {
    type: 'button',
    checkboxLabel: '取消检核',
    bgColor: '#1890FF'
  },
  {
    type: 'button',
    checkboxLabel: '生成指令单',
    bgColor: '#1890FF'
  },
  {
    type: 'button',
    checkboxLabel: '导出指令单',
    bgColor: '#1890FF'
  },
  {
    type: 'button',
    checkboxLabel: '转配色BOM'
  },
  {
    type: 'button',
    checkboxLabel: '转型体资料'
  }
])
const selectedLists = ref([]) as any
const selectTableList = (selectedList: any) => {
  selectedLists.value = selectedList
}
const dbClick = (row: any) => {
  ElMessageBox.confirm('是否刷新型体？', {
    confirmButtonText: '确认',
    cancelButtonText: '取消',
    type: 'warning'
  })
    .then(async () => {
      const res = (await LoginWork.post('/style/RefreshTheBody', row)) as any
      if (res.code === 200) {
        JMessage.success('刷新型体成功')
        getTableList(0)
      } else {
        JMessage.error(res.message)
      }
    })
    .catch(() => {
      ElMessage({
        type: 'info',
        message: '取消修改'
      })
    })
}
const findClicked = async (content: string) => {
  if (content === '置空') {
    formList.value.forEach((item: any) => {
      item.inputValue = ''
      item.selectValue = ''
      item.dateValue = ''
    })
    getTableList()
  }
  if (content === '新增指令') {
    if (
      !formList.value.find((item: any) => item.dateLabel && Jzhcn.Find[item.dateLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '客人交期')
        ?.dateValue
    ) {
      JMessage.error('请选择客人交期')
      return
    }
    if (
      !formList.value.find((item: any) => item.dateLabel && Jzhcn.Find[item.dateLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '下单日期')
        ?.dateValue
    ) {
      JMessage.error('请选择下单日期')
      return
    }
    const res = (await SynchronizationLoginWork.post('/style/addStyle', {
      lotNo: formList.value.find(
        (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入指令'
      )?.inputValue, //	指令
      style: formList.value.find(
        (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入工厂型体'
      )?.inputValue, //	型体
      color:
        formList.value
          .find((item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '颜色名称  颜色代码')
          ?.selectValue.split('  ')[0] || '', //	颜色名称  颜色代码
      colorCode:
        formList.value
          .find((item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '颜色名称  颜色代码')
          ?.selectValue.split('  ')[1] || '', //	颜色代码
      custom: formList.value.find((item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '品牌')
        ?.selectValue, //	品牌
      customPo: formList.value.find(
        (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入合同号'
      )?.inputValue, //	合同号
      cutNo: formList.value.find((item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '冲刀')
        ?.selectValue, //	冲刀
      deliveryEndDate:
        formList.value.find((item: any) => item.dateLabel && Jzhcn.Find[item.dateLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '客人交期')
          ?.dateValue?.[1] === undefined
          ? ''
          : formList.value.find((item: any) => item.dateLabel && Jzhcn.Find[item.dateLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '客人交期')
              ?.dateValue?.[1] + ' 00:00:00', //	交期日期结束
      deliveryStartDate:
        formList.value.find((item: any) => item.dateLabel && Jzhcn.Find[item.dateLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '客人交期')
          ?.dateValue?.[0] === undefined
          ? ''
          : formList.value.find((item: any) => item.dateLabel && Jzhcn.Find[item.dateLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '客人交期')
              ?.dateValue?.[0] + ' 00:00:00', //	交期日期开始
      developmentNo: formList.value.find(
        (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入客人货号'
      )?.inputValue, //	客人货号
      lastNo: formList.value.find((item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '楦头')
        ?.selectValue, //	楦头
      moldNo: formList.value.find((item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '底模')
        ?.selectValue, //	底模
      orderEndDate:
        formList.value.find((item: any) => item.dateLabel && Jzhcn.Find[item.dateLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '下单日期')
          ?.dateValue?.[1] === undefined
          ? ''
          : formList.value.find((item: any) => item.dateLabel && Jzhcn.Find[item.dateLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '下单日期')
              ?.dateValue?.[1] + ' 00:00:00', //	下单日期结束
      orderStartDate:
        formList.value.find((item: any) => item.dateLabel && Jzhcn.Find[item.dateLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '下单日期')
          ?.dateValue?.[0] === undefined
          ? ''
          : formList.value.find((item: any) => item.dateLabel && Jzhcn.Find[item.dateLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '下单日期')
              ?.dateValue?.[0] + ' 00:00:00', //	下单日期开始
      season: formList.value.find((item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '季度')
        ?.selectValue, //	季度
      soleVendor: formList.value.find((item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '大底厂商')
        ?.selectValue, //	大底厂商
      styleType: formList.value.find((item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '新旧型体')
        ?.selectValue //	新旧型体
    })) as any
    if (res.code === 200) {
      JMessage.success('新增成功')
      getTableList()
    } else {
      JMessage.error(res.message)
    }
  }
  if (content === '检核') {
    if (selectedLists.value.length === 0) {
      JMessage.error('请选择要检核的行')
      return
    }
    const res = (await SynchronizationLoginWork.post(
      `/style/getLotNoCheck/${0}`,
      selectedLists.value.map((item: any) => {
        return { lotNo: item.lotNo }
      })
    )) as any
    if (res.code === 200) {
      JMessage.success('检核成功')
      getTableList()
    } else {
      JMessage.error(res.message)
    }
  }
  if (content === '取消检核') {
    if (selectedLists.value.length === 0) {
      JMessage.error('请选择要取消检核的行')
      return
    }
    const res = (await SynchronizationLoginWork.post(
      `/style/getLotNoCheck/${1}`,
      selectedLists.value.map((item: any) => {
        return { lotNo: item.lotNo }
      })
    )) as any
    if (res.code === 200) {
      JMessage.success('取消检核成功')
      getTableList()
    } else {
      JMessage.error(res.message)
    }
  }
  if (content === '指令复制') {
    lotNoVisible.value = true
  }
  if (content === '计算中间码') {
    const res = (await SynchronizationLoginWork.post(`/style/getMiddleCode`, selectedLists.value)) as any
    if (res.code === 200) {
      JMessage.success('计算中间码成功')
      getTableList()
    } else {
      JMessage.error(res.message)
    }
  }
  if (content === '生成指令单') {
    const res = (await SynchronizationLoginWork.post(
      `/style/getUsageGenerate`,
      selectedLists.value.map((item: any) => {
        item.newLotNo = item.baseSize
        return item
      })
    )) as any
    if (res.code === 200) {
      JMessage.success('生成指令单成功')
      getTableList()
    } else {
      JMessage.error(res.message)
    }
  }
  if (content === '整单删除') {
    const res = (await SynchronizationLoginWork.post(`/style/getStyleDelete`, {
      lotNo: currentTableRow.value.lotNo
    })) as any
    if (res.code === 200) {
      JMessage.success('整单删除成功')
      getTableList()
    } else {
      JMessage.error(res.message)
    }
  }
  if (content === '导出指令单') {
    const res = (await fileRequest.post(`/style/ExportInstructionSheet`, {
      ...currentTableRow.value
    })) as any
    const link = document.createElement('a') // 利用a标签自定义下载文件名
    let blob = new Blob([res.data]) // 创建Blob对象，设置文件类型
    link.style.display = 'none'
    //设置连接
    link.href = window.URL.createObjectURL(blob)
    const FileName = decodeURI(res.headers['content-disposition'].split(`filename=`)[1])
    link.download = FileName //自定义文件名字
    document.body.appendChild(link)
    //模拟点击事件
    link.click()
    document.body.removeChild(link)
  }
  if (content === '转配色BOM') {
    router.push('/ControlDepartment/MaterialManagement/BulkQuantityFile')
  }
  if (content === '转型体资料') {
    router.push(`/ControlDepartment/MaterialManagement/BulkBodyFile?style=${currentTableRow.value.style}`)
  }
}
// 复制Dialog点击确认按钮
const ClickCopyLotNo = async () => {
  const res = (await SynchronizationLoginWork.post(`/style/getLotNoCopy`, {
    lotNo: currentTableRow.value.lotNo,
    newLotNo: copyLotNo.value
  })) as any
  if (res.code === 200) {
    JMessage.success('指令复制成功')
    getTableList()
    lotNoVisible.value = false
  } else {
    JMessage.error(res.message)
  }
}
const tableData = ref<any>([])
const imgList = ref([])
const tableHeader = ref([
  {
    type: 'img',
    label: '图片',
    fixed: true,
    prop: 'photoPath',
    srcList: imgList,
    width: 50
  },
  {
    backgroundColor: true,
    label: '指令',
    prop: 'lotNo',
    width: 85,
    change: true
  },
  {
    change: true,
    label: '工厂型体',
    prop: 'style',
    width: 100
  },
  {
    disable: true,
    type: 'select',
    label: '新旧型体',
    prop: 'styleType',
    width: 60
  },
  {
    change: true,
    label: '颜色代码',
    prop: 'colorCode',
    width: 100
  },
  {
    change: true,
    label: '颜色',
    prop: 'color',
    width: 100
  },
  {
    label: '合同号',
    prop: 'customPo',
    width: 90
  },
  {
    type: 'dateSingle',
    label: '下单日期',
    prop: 'orderDate',
    width: 110
  },
  {
    type: 'dateSingle',
    label: '客人交期',
    prop: 'deliveryDate',
    width: 110
  },
  {
    label: '品牌',
    prop: 'custom',
    width: 65
  },
  {
    label: '季度',
    prop: 'season',
    width: 90
  },
  {
    label: '客人货号',
    prop: 'developmentNo',
    width: 90
  },
  {
    label: '冲刀',
    prop: 'cutNo',
    width: 90
  },
  {
    label: '底模',
    prop: 'moldNo',
    width: 90
  },
  {
    label: '楦头',
    prop: 'lastNo',
    width: 90
  },
  {
    label: '大底厂商',
    prop: 'soleVendor',
    width: 90
  },
  {
    label: '订单数',
    prop: 'orderQty',
    width: 50
  },
  {
    label: '预补数',
    prop: 'surplusQty',
    width: 50
  },
  {
    label: '基本码',
    prop: 'baseSize',
    width: 50
  },
  {
    label: '中间码',
    prop: 'mSize',
    width: 50
  },
  {
    label: '检核状态',
    prop: 'cfmFlag',
    width: 50,
    change: true
  },
  {
    label: '生成状态',
    prop: 'generateFlag',
    width: 50,
    change: true
  }
])
const formList2 = ref([
  {
    type: 'checkbox',
    checkboxLabel: '全套',
    checked: false
  },
  {
    type: 'checkbox',
    checkboxLabel: '主面料',
    checked: false
  },
  {
    type: 'checkbox',
    checkboxLabel: '冲裁',
    checked: false
  },
  {
    type: 'checkbox',
    checkboxLabel: '工艺',
    checked: false
  },
  {
    type: 'checkbox',
    checkboxLabel: '配套',
    checked: false
  },
  {
    type: 'checkbox',
    checkboxLabel: '针车',
    checked: false
  },
  {
    type: 'checkbox',
    checkboxLabel: '大底',
    checked: false
  },
  {
    type: 'checkbox',
    checkboxLabel: '成型',
    checked: false
  },
  {
    type: 'checkbox',
    checkboxLabel: '外发',
    checked: false
  },
  {
    type: 'input',
    inputPlaceholder: '',
    inputValue: '',
    inputLabel: '制单人',
    inputDisabled: true
  },
  {
    type: 'input',
    inputPlaceholder: '',
    inputValue: '',
    inputLabel: '制单日期',
    inputDisabled: true
  },
  {
    type: 'input',
    inputPlaceholder: '',
    inputValue: '',
    inputLabel: '检核日期',
    inputDisabled: true
  },
  {
    type: 'input',
    inputPlaceholder: '',
    inputValue: '',
    inputLabel: '指令生成日期',
    inputDisabled: true
  },
  {
    type: 'input',
    inputPlaceholder: '',
    inputValue: '',
    inputLabel: '备注',
    inputDisabled: true
  }
])
// 总计
interface summaryDataType {
  index: number
  num: number | undefined
}
const summaryData = ref<summaryDataType[]>([
  {
    index: 17,
    num: 0
  },
  {
    index: 18,
    num: 0
  }
])
// 分页器
const currentPage = ref(1)
const pageSize = ref(40)
const total = ref(0)
const handleSizeChange = (val: number) => {
  pageSize.value = val
  getTableList()
}
const handleCurrentChange = (val: number) => {
  currentPage.value = val
  getTableList()
}
const isLoading = ref(true)
// 获取表数据
const getTableList = debounce(async (status: any = null, changeColor: boolean = false) => {
  isLoading.value = true
  let tableDataList = await service.post<any, any>('/style/getStyleData', {
    lotNo: formList.value.find(
      (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入指令'
    )?.inputValue, //	指令
    style: formList.value.find(
      (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入工厂型体'
    )?.inputValue, //	型体
    color: formList.value
      .find((item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '颜色名称  颜色代码')
      ?.selectValue.split('  ')[0], //	颜色名称
    colorCode: formList.value
      .find((item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '颜色名称  颜色代码')
      ?.selectValue.split('  ')[1], //	颜色代码
    custom: formList.value.find((item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '品牌')
      ?.selectValue, //	品牌
    customPo: formList.value.find(
      (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入合同号'
    )?.inputValue, //	合同号
    cutNo: formList.value.find((item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '冲刀')
      ?.selectValue, //	冲刀
    deliveryEndDate:
      formList.value.find((item: any) => item.dateLabel && Jzhcn.Find[item.dateLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '客人交期')
        ?.dateValue?.[1] === undefined
        ? ''
        : formList.value.find((item: any) => item.dateLabel && Jzhcn.Find[item.dateLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '客人交期')
            ?.dateValue?.[1] + ' 00:00:00', //	交期日期结束
    deliveryStartDate:
      formList.value.find((item: any) => item.dateLabel && Jzhcn.Find[item.dateLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '客人交期')
        ?.dateValue?.[0] === undefined
        ? ''
        : formList.value.find((item: any) => item.dateLabel && Jzhcn.Find[item.dateLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '客人交期')
            ?.dateValue?.[0] + ' 00:00:00', //	交期日期开始
    developmentNo: formList.value.find(
      (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入客人货号'
    )?.inputValue, //	客人货号
    lastNo: formList.value.find((item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '楦头')
      ?.selectValue, //	楦头
    moldNo: formList.value.find((item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '底模')
      ?.selectValue, //	底模
    orderEndDate:
      formList.value.find((item: any) => item.dateLabel && Jzhcn.Find[item.dateLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '下单日期')
        ?.dateValue?.[1] === undefined
        ? ''
        : formList.value.find((item: any) => item.dateLabel && Jzhcn.Find[item.dateLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '下单日期')
            ?.dateValue?.[1] + ' 00:00:00', //	下单日期结束
    orderStartDate:
      formList.value.find((item: any) => item.dateLabel && Jzhcn.Find[item.dateLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '下单日期')
        ?.dateValue?.[0] === undefined
        ? ''
        : formList.value.find((item: any) => item.dateLabel && Jzhcn.Find[item.dateLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '下单日期')
            ?.dateValue?.[0] + ' 00:00:00', //	下单日期开始
    pageNum: currentPage.value, //		intege
    pageSize: pageSize.value, //		intege
    season: formList.value.find((item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '季度')
      ?.selectValue, //	季度
    soleVendor: formList.value.find((item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '大底厂商')
      ?.selectValue, //	大底厂商
    styleType: formList.value.find((item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '新旧型体')
      ?.selectValue, //	新旧型体
    status //	状态
  })
  // 判断表一
  if (tableDataList.styleDetails.length === 0) {
    tableData.value = []
    tableData2.value = []
    tableData4.value = []
    tableData5.value = []
    tableData6.value = []
    tableData7.value = []
    tableData8.value = []
    tableData9.value = []
    tableData10.value = []
    tableData11.value = []
    tableData12.value = []
    currentTableRow.value = {}
    isLoading.value = false
    return
  }

  isLoading.value = false
  imgList.value = tableDataList.styleDetails.map((item: any) => {
    return item.photoPath
  })
  tableData.value = tableDataList.styleDetails.map((item: any) => {
    item.change = 'Y'
    item.styleType = {
      selectValue: item.styleType,
      options: [
        {
          label: '新款',
          value: '新款'
        },
        {
          label: '旧款',
          value: '旧款'
        }
      ]
    }
    if (item.cfmFlag === 'Y') {
      item.backgroundColor = '#1CD66C'
      item.change = false
      item.disable = true
    }
    return item
  })
  total.value = tableDataList.total
  console.log(changeColor)

  currentRow(currentTableRow.value, '', '', '', changeColor)
  if (tableDataList.orderCount !== null) {
    summaryData.value[0].num = tableDataList.orderCount.orderCount
    summaryData.value[1].num = tableDataList.orderCount.surplusCount
  }
}, 500)
watch(
  formList.value[1],
  debounce(async () => {
    formList.value
      .find((item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '颜色名称  颜色代码')
      .selectOptions.splice(0)
    const res = (await Synchronization.post('/Cargo/getDevelopBomPhotoList', {
      colorCode: '',
      companyId: '',
      pageNum: '',
      pageSize: '',
      styleColor: '',
      styleNo: formList.value.find(
        (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入工厂型体'
      )?.inputValue
    })) as any
    res.list.forEach((item: any) => {
      formList.value
        .find((item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '颜色名称  颜色代码')
        .selectOptions.push({
          value: `${item.styleColor}  ${item.colorCode}`,
          label: `${item.styleColor}  ${item.colorCode}`
        })
    })

    const res2 = (await Synchronization.post('/style/getStyleCondition', {
      lotNo: '',
      style: formList.value.find(
        (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入工厂型体'
      )?.inputValue
    })) as any
    if (!res2) return
    formList.value.find((item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '品牌').selectValue =
      res2.custNo
    formList.value.find(
      (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入客人货号'
    ).inputValue = res2.devCode
    formList.value.find((item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '大底厂商').selectValue =
      res2.soleVendor
    formList.value.find((item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '楦头').selectValue =
      res2.lastMold
    formList.value.find((item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '冲刀').selectValue =
      res2.cutTool
    formList.value.find((item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '底模').selectValue =
      res2.solePart
  }, 500)
)
watch(
  () =>
    formList.value.map((item: any) => {
      item.selectValue, item.inputValue, item.dateValue, item.checked
    }),
  () => {
    currentTableRow.value = {}
    getTableList()
  }
)
// 修改指令明细表格
const getFormateTable = (row: any = tableData.value[0]) => {
  const obj = {
    ...row,
    deliveryDate: row.deliveryDate + ' 00:00:00',
    orderDate: row.orderDate + ' 00:00:00'
  }
  const table = formateData([obj])
  return table
}
const confirmChange = async (row: any, fn: any, current: any) => {
  const table = getFormateTable(row)
  const res = (await SynchronizationLoginWork.put('/style/getStyleDetailUpdate', table[0])) as any
  if (res.code === 200) {
    JMessage.success('修改成功')
  } else {
    JMessage.error(res.message)
  }
  getTableList()
}
const selectValChange = async (row: any, currentLabel: any) => {
  const table = getFormateTable(row)
  console.log(currentLabel, table[0])
  const res = (await SynchronizationLoginWork.put('/style/getStyleDetailUpdate', table[0])) as any
  if (res.code === 200) {
    JMessage.success('修改成功')
  } else {
    JMessage.error(res.message)
  }
  getTableList()
}
// 点击当前行
const currentTableRow = ref(tableData.value[0]) as any
const currentRowRef = ref('') as any
const currentRow = async (row: any = tableData.value[0] ? tableData.value[0] : {}, columns: any, item: any, e: any, changeColor = false) => {
  row.processAll === 'Y' ? (formList2.value[0].checked = true) : (formList2.value[0].checked = false)
  row.processUpper === 'Y' ? (formList2.value[1].checked = true) : (formList2.value[1].checked = false)
  row.processCut01 === 'Y' ? (formList2.value[2].checked = true) : (formList2.value[2].checked = false)
  row.processCut02 === 'Y' ? (formList2.value[3].checked = true) : (formList2.value[3].checked = false)
  row.processCut03 === 'Y' ? (formList2.value[4].checked = true) : (formList2.value[4].checked = false)
  row.processStitch === 'Y' ? (formList2.value[5].checked = true) : (formList2.value[5].checked = false)
  row.processSole === 'Y' ? (formList2.value[6].checked = true) : (formList2.value[6].checked = false)
  row.processLast === 'Y' ? (formList2.value[7].checked = true) : (formList2.value[7].checked = false)
  row.outFlag === 'Y' ? (formList2.value[8].checked = true) : (formList2.value[8].checked = false)
  formList2.value[9].inputValue = row.userId
  formList2.value[10].inputValue = row.sysDate
  formList2.value[11].inputValue = row.cfmDate
  formList2.value[12].inputValue = row.generateDate
  formList2.value[13].inputValue = row.lotRemark

  // 指令明细
  await getTableList2(row.lotNo)
  currentTableRow.value = row
  currentLotNo.value = row.lotNo || ''
  getTableList999(value.value)
  getPoNumberSizeData()
  console.log(changeColor)
  if (changeColor) {
    const list = document.querySelectorAll('.el-table__row')
    list.forEach((item: any) => {
      if (item.textContent === currentRowRef.value) {
        item.className = 'el-table__row current-row'
      } else {
        item.className = 'el-table__row'
      }
    })
  } else {
    console.log(222)
    currentRowRef.value = document.querySelector('.current-row')?.textContent
  }
}
// 修改指令明细下的单选
const findClicked2 = (content: any) => {
  ElMessageBox.confirm('是否修改？', {
    confirmButtonText: '确认',
    cancelButtonText: '取消',
    type: 'warning'
  })
    .then(async () => {
      const table = getFormateTable(currentTableRow.value)
      formList2.value[0].checked === true ? (table[0].processAll = 'Y') : (table[0].processAll = '')
      formList2.value[1].checked === true ? (table[0].processUpper = 'Y') : (table[0].processUpper = '')
      formList2.value[2].checked === true ? (table[0].processCut01 = 'Y') : (table[0].processCut01 = '')
      formList2.value[3].checked === true ? (table[0].processCut02 = 'Y') : (table[0].processCut02 = '')
      formList2.value[4].checked === true ? (table[0].processCut03 = 'Y') : (table[0].processCut03 = '')
      formList2.value[5].checked === true ? (table[0].processStitch = 'Y') : (table[0].processStitch = '')
      formList2.value[6].checked === true ? (table[0].processSole = 'Y') : (table[0].processSole = '')
      formList2.value[7].checked === true ? (table[0].processLast = 'Y') : (table[0].processLast = '')
      formList2.value[8].checked === true ? (table[0].outFlag = 'Y') : (table[0].outFlag = '')
      const res = (await SynchronizationLoginWork.put('/style/getStyleDetailUpdate', table[0])) as any
      if (res.code === 200) {
        JMessage.success('修改成功')
        getTableList()
      } else {
        JMessage.error(res.message)
      }
    })
    .catch(() => {
      ElMessage({
        type: 'info',
        message: '取消修改'
      })
      getTableList()
    })
}
onMounted(() => {
  getTableList(0)
})

// 表二模块
const tableHeader2 = ref([
  {
    label: '号码',
    prop: 'sizeNo',
    width: 50,
    change: true
  },
  {
    label: '订单数',
    prop: 'orderQty',
    width: 50,
    change: true
  },
  {
    label: '预补数',
    prop: 'surplusQty',
    width: 50
  }
])
const tableData2 = ref([])
const summaryData2 = ref<summaryDataType[]>([
  {
    index: 1,
    num: 0
  },
  {
    index: 2,
    num: 0
  }
])
const getTableList2 = async (lotNo: any = tableData.value[0].lotNo) => {
  const tableDataList = (await service.post('/style/getStyleSizeData', { lotNo })) as any
  tableData2.value = tableDataList.codeDetails.map((item: any) => {
    item.change = 'Y'
    item.disableConfirm = true
    return item
  })
  if (tableDataList.codeDetailsSum) {
    summaryData2.value[0].num = tableDataList.codeDetailsSum.orderCount
    summaryData2.value[1].num = tableDataList.codeDetailsSum.surplusCount
  }
  // if (tableData2.value.length === 0) {
  //   disabledValue2.value = false
  // } else {
  //   disabledValue2.value = true
  // }
}
// 修改指令明细（表二）
const confirmChange2 = async (row: any, fn: any) => {
  // const res = (await SynchronizationLoginWork.post('/style/getStyleSizeDataUpdate', {
  //   ...row,
  //   lotNo: currentTableRow.value.lotNo
  // })) as any
  // if (res.code === 200) {
  //   JMessage.success('修改成功')
  //   getTableList(0, currentTableRow.value)
  // } else {
  //   JMessage.error(res.message)
  // }
}
const saveTableList2 = async () => {
  // 如果后端要Number，但是现在发的也是字符串也并保存上了
  const res = (await SynchronizationLoginWork.post(
    '/style/getStyleSizeDataUpdate',
    tableData2.value.map((item: any) => {
      if (item.surplusQty === '') item.surplusQty = null
      item.lotNo = currentTableRow.value.lotNo
      return item
    })
  )) as any
  if (res.code === 200) {
    JMessage.success('修改成功')
    getTableList(0, true)
  } else {
    JMessage.error(res.message)
  }
}

// PO号码明细下拉框模块
const value = ref(0) // PO号码明细的v-model
const options = [
  {
    value: 0,
    label: 'PO号码明细'
  },
  {
    value: 1,
    label: '指令用量明细'
  },
  {
    value: 2,
    label: '配色注意事项'
  },
  {
    value: 3,
    label: '型体配楦明细'
  },
  {
    value: 4,
    label: '配色BOM资料'
  },
  {
    value: 5,
    label: '各节点明细'
  }
] // PO号码明细下拉框数组
const EndSelectVal = (val: any) => {
  getTableList999(val)
} // change事件
const getTableList999 = async (num: any = 0) => {
  if (tableData.value.length === 0) {
    // 判断表一
    tableData.value = []
    tableData2.value = []
    tableData4.value = []
    tableData5.value = []
    tableData6.value = []
    tableData7.value = []
    tableData8.value = []
    tableData9.value = []
    tableData10.value = []
    tableData11.value = []
    tableData12.value = []
    currentTableRow.value = {}
    return
  }
  let { lotNo, color, style, colorCode }: any = currentTableRow.value
  // PO号码明细
  if (num === 0) {
    getPoNumberDetails()
  }
  // 指令用量明细
  if (num === 1) {
    getUsageDetails()
  }
  // 配色注意事项
  if (num === 2) {
    const res = await Synchronization.post<any, any>('/Cargo/getNotesForFilingList', {
      styleColor: color,
      styleNo: style
    })
    tableData6.value = res
  }
  // 型体配楦明细
  if (num === 3) {
    tableData7.value = await Synchronization.get<any, any>(`/style/getStyleToLastNoDetails?style=${currentTableRow.value.style}`)
  }
  // 配色BOM资料
  if (num === 4) {
    tableData8.value = await Synchronization.post<any, any>('/style/getColorBOMInfo', { color, style })
  }
  // 各节点生产明细
  if (num === 5) {
    getLastDetails()
    getProdDetails()
    getSoleDetails()
  }
}

// 美码/英码下拉框模块
const options2 = ref([]) as any // 美码/英码下拉框数组
// 美码/英码的disabled修改
const disabledValue2 = ref(false)

// JDialog模块
const JDialogHeader = ref([]) as any
const clickAdd = async (obj: any) => {
  for (const key in obj) {
    if (key.includes('qty')) {
      obj[key] = null
    }
  }
  let isCorrect = true as boolean
  JDialogHeader.value = []
  // 获取型体配楦接口
  const StyleToLast = await Synchronization.get<any, any>(`/style/getStyleToLastNoDetails?style=${currentTableRow.value.style}`)
  StyleToLast.forEach((item: any) => {
    if (!tableHeader4.value.find((item2: any) => item2.label === item.sizeNo + '#')) {
      isCorrect = false
      return
    }
    const prop = tableHeader4.value.find((item2: any) => item2.label === item.sizeNo + '#').prop
    JDialogHeader.value.push({
      label: item.sizeNo + '#',
      prop,
      value: null
      // type: 'number'
    })
  })
  if (isCorrect == false) JMessage.error('请选择正确的码制')
} // JDialog添加按钮点击函数
const clickEdit = async (obj: any) => {
  let isCorrect = true as boolean
  JDialogHeader.value = []
  // 获取型体配楦接口
  const StyleToLast = await Synchronization.get<any, any>(`/style/getStyleToLastNoDetails?style=${currentTableRow.value.style}`)
  StyleToLast.forEach((item: any) => {
    if (!tableHeader4.value.find((item2: any) => item2.label === item.sizeNo + '#')) {
      isCorrect = false
      return
    }
    const prop = tableHeader4.value.find((item2: any) => item2.label === item.sizeNo + '#').prop
    JDialogHeader.value.push({
      label: item.sizeNo + '#',
      prop
      // type: 'number'
    })
  })
  if (isCorrect == false) JMessage.error('请选择正确的码制')
}
// PO号码明细表模块
const tableData4 = ref([]) as any
const tableHeader4 = ref([
  {
    change: true,
    label: '配码',
    prop: 'groupNo'
  },
  {
    label: 'PO',
    prop: 'poNo'
  },
  {
    label: '装箱方式',
    prop: 'caseType'
  },
  {
    change: true,
    label: '数量',
    prop: 'count'
  },
  {
    change: true,
    label: '码制',
    prop: 'sizeNotice'
  }
]) as any
// 获取PO号码明细表头
const currentPoNumberSizeData = ref([]) as any
const getPoNumberSizeData = async () => {
  await getPoNumberDetails()
  const res = await Synchronization.post<any, any>('/style/getPoNumberSizeData', {
    sizeCode: value2.value.split('  ')[1]
  })
  if (res) {
    currentPoNumberSizeData.value = res
    tableHeader4.value.splice(5, tableHeader4.value.length)
    res.forEach((item: any, index: number) => {
      tableHeader4.value.push({
        label: item.sizeNo,
        prop: 'qty' + (index + 1),
        width: '50'
      })
    })
  }
}
const getPoNumberDetails = async () => {
  const res = (await service.post<any, any>('/style/getPoNumberDetails', {
    lotNo: currentTableRow.value.lotNo
  })) as any
  tableData4.value = res.pcLotGroups.map((item: any) => {
    // if (currentTableRow.value.cfmFlag !== 'Y') {
    //   item.change = 'Y'
    // } else {
    //   item.change = false
    // }
    item.disableConfirm = true
    return item
  })
  summaryData6.value[0].num = res.sum
  if (tableData4.value.length !== 0 && tableData4.value[0].sizeNotice) {
    value2.value = `${tableData4.value[0].sizeNotice}  ${tableData4.value[0].sizeCode}`
  }
  if (tableData4.value.length !== 0) currentRow4()
} // 获取PO号码明细表格
const confirmChange5 = async (row: any, fn: any) => {
  // const res = await SynchronizationLoginWork.post('/style/getPoNumberDetailAdd',{
  //   numberList,
  //   ...obj,
  //   lotNo: currentTableRow.value.lotNo,
  //   groupNo: Number(tableData4.value[tableData4.value.length - 1].groupNo) + 1
  // })
  // const res = await SynchronizationLoginWork.post('/style/getStyleSizeDataUpdate', {
  //   ...row,
  //   lotNo: currentTableRow.value.lotNo
  // }) as any
  // if (res.code === 200) {
  //   JMessage.success('修改成功')
  //   getTableList2(currentTableRow.value.lotNo)
  // } else {
  //   JMessage.error(res.message)
  // }
} // 修改PO号码明细表
const currentTable4Row = ref({}) as any
const currentTable4RowIndex = ref(0) as any
const currentRow4 = (row: any = tableData4.value[0]) => {
  currentTable4RowIndex.value = tableData4.value.findIndex((item: any) => item === row)
  currentTable4Row.value = row
}
const confirmChange4 = debounce(async (row: any, label: any) => {}, 500)

const dialogConfirm = async (obj: any, dialogVisible: any, title: any) => {
  if (title === '添加') {
    if (tableData4.value.length === 1) {
      JMessage.error('不能添加超过两条')
      return
    }
    const numberList = [] as any
    const temObj = {
      qty1: 0,
      qty2: 0,
      qty3: 0,
      qty4: 0,
      qty5: 0,
      qty6: 0,
      qty7: 0,
      qty8: 0,
      qty9: 0,
      qty10: 0,
      qty11: 0,
      qty12: 0,
      qty13: 0,
      qty14: 0,
      qty15: 0,
      qty16: 0,
      qty17: 0,
      qty18: 0,
      qty19: 0,
      qty20: 0,
      qty21: 0,
      qty22: 0,
      qty23: 0,
      qty24: 0,
      qty25: 0,
      qty26: 0,
      qty27: 0,
      qty28: 0,
      qty29: 0,
      qty30: 0,
      qty31: 0,
      qty32: 0,
      qty33: 0,
      qty34: 0,
      qty35: 0,
      qty36: 0,
      qty37: 0,
      qty38: 0,
      qty39: 0,
      qty40: 0
    } as any
    // 计算表格每一列合计
    tableData4.value.forEach((item: any, index: number) => {
      for (const key in item) {
        for (const key2 in temObj) {
          if (key === key2) {
            temObj[key2] += item[key]
          }
        }
      }
    })
    // 表格合计和新增相加
    for (const key in obj) {
      for (const key2 in temObj) {
        if (key === key2) {
          temObj[key2] += Number(obj[key])
        }
      }
    }
    currentPoNumberSizeData.value.forEach((item: any, index: number) => {
      // if (temObj['qty' + (index + 1)] !== 0) {
      numberList.push({
        seqNo: item.seqNo,
        sizeNo: item.sizeNo.slice(0, item.sizeNo.length - 1),
        orderQty: temObj['qty' + (index + 1)]
      })
      // }
    })
    const res = (await SynchronizationLoginWork.post(`/style/getPoNumberDetailAdd`, {
      numberList,
      ...obj,
      lotNo: currentTableRow.value.lotNo,
      groupNo: tableData4.value.length === 0 ? 1 : Number(tableData4.value[tableData4.value.length - 1].groupNo) + 1,
      sizeCode: value2.value.split('  ')[1]
    })) as any
    if (res.code === 200) {
      JMessage.success('新增成功')
      dialogVisible.value = false
    } else {
      JMessage.error(res.message)
    }
  } else if (title === '修改') {
    const numberList = [] as any
    const temObj = {
      qty1: 0,
      qty2: 0,
      qty3: 0,
      qty4: 0,
      qty5: 0,
      qty6: 0,
      qty7: 0,
      qty8: 0,
      qty9: 0,
      qty10: 0,
      qty11: 0,
      qty12: 0,
      qty13: 0,
      qty14: 0,
      qty15: 0,
      qty16: 0,
      qty17: 0,
      qty18: 0,
      qty19: 0,
      qty20: 0,
      qty21: 0,
      qty22: 0,
      qty23: 0,
      qty24: 0,
      qty25: 0,
      qty26: 0,
      qty27: 0,
      qty28: 0,
      qty29: 0,
      qty30: 0,
      qty31: 0,
      qty32: 0,
      qty33: 0,
      qty34: 0,
      qty35: 0,
      qty36: 0,
      qty37: 0,
      qty38: 0,
      qty39: 0,
      qty40: 0
    } as any
    currentTable4Row.value = obj
    tableData4.value.splice(currentTable4RowIndex.value, 1)
    tableData4.value.push(obj)
    // 计算表格每一列合计
    tableData4.value.forEach((item: any, index: number) => {
      for (const key in item) {
        for (const key2 in temObj) {
          if (key === key2) {
            temObj[key2] += Number(item[key])
          }
        }
      }
    })
    currentPoNumberSizeData.value.forEach((item: any, index: number) => {
      numberList.push({
        seqNo: item.seqNo,
        sizeNo: item.sizeNo.slice(0, item.sizeNo.length - 1),
        orderQty: temObj['qty' + (index + 1)]
      })
    })
    const res = (await SynchronizationLoginWork.post(`/style/getPoNumberDetailAdd`, {
      numberList,
      ...obj,
      lotNo: currentTableRow.value.lotNo,
      groupNo: currentTable4Row.value.groupNo,
      sizeCode: value2.value.split('  ')[1]
    })) as any
    if (res.code === 200) {
      JMessage.success('修改成功')
      dialogVisible.value = false
    } else {
      JMessage.error(res.message)
    }
  }
  getTableList(0, true)
  getPoNumberDetails()
} // PO号码明细表格增加
const removeOne = async () => {
  ElMessageBox.confirm('是否删除该条数据?', 'Warning', {
    confirmButtonText: '确认',
    cancelButtonText: '取消',
    type: 'warning'
  })
    .then(async () => {
      let isOne = true
      if (tableData4.value.length > 1) isOne = false
      let res = {} as any
      const numberList = [] as any
      const temObj = {
        qty1: 0,
        qty2: 0,
        qty3: 0,
        qty4: 0,
        qty5: 0,
        qty6: 0,
        qty7: 0,
        qty8: 0,
        qty9: 0,
        qty10: 0,
        qty11: 0,
        qty12: 0,
        qty13: 0,
        qty14: 0,
        qty15: 0,
        qty16: 0,
        qty17: 0,
        qty18: 0,
        qty19: 0,
        qty20: 0,
        qty21: 0,
        qty22: 0,
        qty23: 0,
        qty24: 0,
        qty25: 0,
        qty26: 0,
        qty27: 0,
        qty28: 0,
        qty29: 0,
        qty30: 0,
        qty31: 0,
        qty32: 0,
        qty33: 0,
        qty34: 0,
        qty35: 0,
        qty36: 0,
        qty37: 0,
        qty38: 0,
        qty39: 0,
        qty40: 0
      } as any
      // 计算表格每一列合计
      if (!isOne) tableData4.value.splice(currentTable4RowIndex.value, 1)
      tableData4.value.forEach((item: any, index: number) => {
        for (const key in item) {
          for (const key2 in temObj) {
            if (key === key2) {
              temObj[key2] += item[key]
            }
          }
        }
      })
      currentPoNumberSizeData.value.forEach((item: any, index: number) => {
        // if (temObj['qty' + (index + 1)] !== 0) {
        numberList.push({
          seqNo: item.seqNo,
          sizeNo: item.sizeNo.slice(0, item.sizeNo.length - 1),
          orderQty: temObj['qty' + (index + 1)]
        })
        // }
      })
      if (!isOne) {
        res = (await SynchronizationLoginWork.post(`/style/getPoNumberDetailDel`, {
          ...currentTable4Row.value,
          numberList,
          lotNo: currentTableRow.value.lotNo
        })) as any
      } else {
        res = (await SynchronizationLoginWork.post(`/style/getPoNumberDetailDel`, {
          ...currentTable4Row.value,
          numberList: numberList.map((item: any) => {
            item.orderQty = 0
            return item
          }),
          lotNo: currentTableRow.value.lotNo
        })) as any
      }
      if (res.code === 200) {
        JMessage.success('删除成功')
        getPoNumberDetails()
        getTableList2(currentTableRow.value.lotNo)
      } else {
        JMessage.error(res.message)
        currentRow()
      }
    })
    .catch(() => {
      ElMessage({
        type: 'info',
        message: '取消删除'
      })
    })
} // PO号码明细表格删除

// 指令用量明细表模块
const tableHeader5 = ref([
  {
    label: '序号',
    prop: 'seqNo',
    width: 50
  },
  {
    label: '部位',
    prop: 'partName'
  },
  {
    label: '物料编号',
    prop: 'mtlNo',
    width: 120
  },
  {
    label: '段',
    prop: 'segment',
    width: 50
  },
  {
    label: '分类',
    prop: 'mtlTypeNo'
  },
  {
    label: '分类名称',
    prop: 'typeName'
  },
  {
    label: '材料颜色',
    prop: 'mtlColor'
  },
  {
    label: '材料名称',
    prop: 'mtlName',
    width: 200
  },
  {
    label: '规格',
    prop: 'mtlSpec'
  },
  {
    label: '单位',
    prop: 'mtlUnit'
  },
  {
    label: '尺码起',
    prop: 'size1'
  },
  {
    label: '尺码止',
    prop: 'size2'
  },
  {
    label: '单耗',
    prop: 'stdUsage'
  },
  {
    label: '用量',
    prop: 'ttlUsage'
  },
  {
    label: '预加量',
    prop: 'addUsage'
  },
  {
    label: '比例%',
    prop: 'proportion'
  },
  {
    label: '备注',
    prop: 'remark'
  }
])
const tableData5 = ref([])
const getUsageDetails = async () => {
  const res = (await service.post<any, any>('/style/getUsageDetails', {
    lotNo: currentTableRow.value.lotNo
  })) as any
  tableData5.value = res
} // 获取指令用量明细

// 配色注意事项表模块
const tableHeader6 = ref([
  {
    label: '序号',
    prop: 'seqNo',
    width: 50
  },
  {
    width: 150,
    label: '事项名称',
    prop: 'seqName'
  },
  {
    label: '生产注意事项',
    prop: 'prodMemo'
  }
])
const tableData6 = ref([])

// 型体配楦明细表模块
const tableHeader7 = ref([
  {
    label: '鞋码',
    prop: 'sizeNo'
  },
  {
    label: '冲刀',
    prop: 'cutSize'
  },
  {
    label: '楦头',
    prop: 'lastSize'
  },
  {
    label: '大底',
    prop: 'soleSize'
  },
  {
    label: '中底',
    prop: 'insoleSize'
  }
])
const tableData7 = ref([])

// 配色BOM资料模块
const tableHeader8 = ref([
  {
    label: '序号',
    prop: 'seqNo',
    width: 50
  },
  {
    label: '部位',
    prop: 'partName',
    width: 150
  },
  {
    label: '分段',
    prop: 'segment',
    width: 50
  },
  {
    label: '片数',
    prop: 'meiyou',
    width: 50
  },
  {
    label: '分类名称',
    prop: 'typeName'
  },
  {
    label: '物料编码',
    prop: 'mtlNo',
    width: 150
  },
  {
    label: '材料颜色',
    prop: 'mtlColor'
  },
  {
    label: '材料名称',
    prop: 'mtlName',
    width: 300
  },
  {
    label: '规格',
    prop: 'mtlSpec'
  },
  {
    label: '单位',
    prop: 'mtlUnit',
    width: 50
  },
  {
    label: '尺码起',
    prop: 'size1'
  },
  {
    label: '尺码止',
    prop: 'size2'
  },
  {
    label: '用量',
    prop: 'usage'
  },
  {
    label: '计算方式',
    prop: 'usageType'
  },
  {
    label: '领用部门',
    prop: 'drawDept'
  },
  {
    label: '捡料',
    prop: 'noLotUsage'
  },
  {
    label: '主辅料',
    prop: 'mtlProperty'
  }
])
const tableData8 = ref([])

// 各节点生产明细模块
const tableHeader9 = ref([
  {
    label: '号码',
    prop: 'sizeNo',
    width: 80
  },
  {
    label: '订单数',
    prop: 'orderQty',
    width: 80
  },
  {
    label: '预补数',
    prop: 'surplusQty',
    width: 80
  }
])
const tableData9 = ref([])
const tableHeader10 = ref([
  {
    label: '号码',
    prop: 'sizeNo',
    width: 80
  },
  {
    label: '订单数',
    prop: 'orderQty',
    width: 80
  },
  {
    label: '预补数',
    prop: 'surplusQty',
    width: 80
  }
])
const tableData10 = ref([])
const tableHeader11 = ref([
  {
    label: '号码',
    prop: 'sizeNo',
    width: 80
  },
  {
    label: '订单数',
    prop: 'orderQty',
    width: 80
  },
  {
    label: '预补数',
    prop: 'surplusQty',
    width: 80
  }
])
const tableData11 = ref([])
const summaryData3 = ref<summaryDataType[]>([
  {
    index: 1,
    num: 0
  },
  {
    index: 2,
    num: 0
  }
])
const summaryData4 = ref<summaryDataType[]>([
  {
    index: 1,
    num: 0
  },
  {
    index: 2,
    num: 0
  }
])
const summaryData5 = ref<summaryDataType[]>([
  {
    index: 1,
    num: 0
  },
  {
    index: 2,
    num: 0
  }
])
const summaryData6 = ref<summaryDataType[]>([
  {
    index: 3,
    num: 0
  }
])
// 获取表格数据
const getLastDetails = async () => {
  const res = await service.post<any, any>('/style/getLastDetails', {
    lotNo: currentTableRow.value.lotNo
  })
  tableData11.value = res.codeDetails
  summaryData5.value[0].num = res.codeDetailsSum.orderCount
  summaryData5.value[1].num = res.codeDetailsSum.surplusCount
} // 取成型生产号码明细查询
const getProdDetails = async () => {
  const res = await service.post<any, any>('/style/getStitchDetails', {
    lotNo: currentTableRow.value.lotNo
  })
  tableData10.value = res.codeDetails
  summaryData4.value[0].num = res.codeDetailsSum.orderCount
  summaryData4.value[1].num = res.codeDetailsSum.surplusCount
} // 取鞋面生产号码明细查询
const getLastDetailsAdd = async () => {
  const res = (await LoginWork.post('/style/getLastDetailsAdd', {
    lotNo: currentTableRow.value.lotNo
  })) as any
  if (res.code === 200) {
    JMessage.success('取成型生产号码明细成功')
    getLastDetails()
  } else {
    JMessage.error(res.message)
  }
} // 取成型生产号码明细按钮点击事件
const getStitchDetailsAdd = async () => {
  const res = (await LoginWork.post('/style/getStitchDetailsAdd', {
    lotNo: currentTableRow.value.lotNo
  })) as any
  if (res.code === 200) {
    JMessage.success('取鞋面生产号码明细成功')
    getProdDetails()
  } else {
    JMessage.error(res.message)
  }
} // 取鞋面生产号码明细按钮点击事件
const getSoleDetails = async () => {
  const res = await service.post<any, any>('/style/getSoleDetails', {
    lotNo: currentTableRow.value.lotNo
  })
  tableData9.value = res.codeDetails
  summaryData3.value[0].num = res.codeDetailsSum.orderCount
  summaryData3.value[1].num = res.codeDetailsSum.surplusCount
} // 取大底入货号码明细查询
const getSoleDetailsAdd = async () => {
  const res = (await LoginWork.post('/style/getSoleDetailsAdd', {
    lotNo: currentTableRow.value.lotNo
  })) as any
  if (res.code === 200) {
    JMessage.success('取大底入货号码明细成功')
    getSoleDetails()
  } else {
    JMessage.error(res.message)
  }
} // 取大底入货号码明细按钮点击事件

// 获取下拉框数据
const selectList = async () => {
  let res = await service.get<any, any>('/style/getCondition')
  // 底膜
  res.moldNo.forEach((item: any) => {
    if (item === null || item === '') return
    formList.value
      .find((item: any) => item.type === 'select' && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '底模')
      .selectOptions.push({
        optionValue: item,
        optionLabel: item
      })
  })
  // lastNo 楦头
  res.lastNo.forEach((item: any) => {
    if (item === null || item === '') return
    formList.value
      .find((item: any) => item.type === 'select' && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '楦头')
      .selectOptions.push({
        optionValue: item,
        optionLabel: item
      })
  })

  // custom  品牌
  res.custom.forEach((item: any) => {
    if (item === null || item === '') return
    formList.value
      .find((item: any) => item.type === 'select' && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '品牌')
      .selectOptions.push({
        optionValue: item,
        optionLabel: item
      })
  })

  // cutNo 冲刀
  res.cutNo.forEach((item: any) => {
    if (item === null || item === '') return
    formList.value
      .find((item: any) => item.type === 'select' && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '冲刀')
      .selectOptions.push({
        optionValue: item,
        optionLabel: item
      })
  })
  // season 季度
  res.season.forEach((item: any) => {
    if (item === null || item === '') return
    formList.value
      .find((item: any) => item.type === 'select' && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '季度')
      .selectOptions.push({
        optionValue: item,
        optionLabel: item
      })
  })
  // soleVendor 大底厂商
  res.soleVendor.forEach((item: any) => {
    if (item === null || item === '') return
    formList.value
      .find((item: any) => item.type === 'select' && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '大底厂商')
      .selectOptions.push({
        optionValue: item,
        optionLabel: item
      })
  })

  const res2 = (await service.get('/back/getSizeTypeByName')) as any
  options2.value = res2.map((item: any) => {
    return {
      label: item.sizeNotice,
      value: `${item.sizeNotice}  ${item.sizeCode}`
    }
  })
}
onMounted(() => {
  selectList()
})

// 按回车下键
const JRef = ref()
const handleKeyDown = async (e: any, index: any, ref: any) => {
  if (e.key === 'Enter' || e.keyCode === 13) {
    const focusableElements = JRef.value.querySelectorAll('.el-input__inner')
    // 阻止默认的回车行为（比如表单提交等）
    e.preventDefault()
    // 计算下一个可聚焦元素的索引，使用模运算 % 实现循环，当到达最后一个元素时，索引会回到0，即第一个元素
    const nextIndex = (index + 1) % focusableElements.length
    // 将焦点移动到下一个可聚焦元素
    focusableElements[nextIndex].focus()
  }
}
</script>

<style lang="less" scoped>
:deep(.cell:hover) {
  background-color: white !important;
  cursor: pointer;
}

:deep(.el-input__suffix) {
  display: none;
}

:deep(.el-drawer.ttb) {
  height: 85%;
}

.AC {
  align-items: center;
}
</style>
